﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for bzOrder
/// </summary>
public class bzOrder
{
	private dbConnection _DB = null;
    private string _TableName = "bzOrder";
    private string _IDType = "_INT";
    private string _IDCol = "OrderID";
    private string _IDColCate = "";
    private string _TableChild = "";
    private string _Field = "";
    public struct Enable
    {
        private static int _Enabled = 1;
        public static int Enabled { get { return _Enabled; } }

        private static int _Disabled = 0;
        public static int Disabled { get { return _Disabled; } }
    }   
    public bzOrder()
    {
        _DB = new dbConnection();
    }
    public DataTable getTable(string Key, string Enabled, string Page, string Limit, string Status)
    {
        SqlParameter[] p = new SqlParameter[5];
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled);
        p[2] = new SqlParameter("@Page", Page);
        p[3] = new SqlParameter("@Limit", Limit);
        p[4] = new SqlParameter("@Status", Status);
        return _DB.getDataTable(_TableName + "_search", p);

    }
    public long getTotal(string Key, string Enabled, string Status)
    {
        SqlParameter[] p = new SqlParameter[3];
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled);
        p[2] = new SqlParameter("@Status", Status);
        return _DB.getTotalTable(_TableName + "_getTotal", p);
    }
    public DataTable getRecord(string ID, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        p[3] = new SqlParameter("@Enabled", Enabled);
        return _DB.getDataTable("bz_getRecord" + _IDType, p);
    }
    public int deleteRecord(string[] ID)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@TableChild", _TableChild);
            p[2] = new SqlParameter("@IDCol", _IDCol);
            p[3] = new SqlParameter("@IDValue", str);
            count += _DB.updateData("bz_deleteRecord" + _IDType, p);
        }
        return count;
    }
    public int activeRecord(string[] ID, string Enabled)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@IDCol", _IDCol);
            p[2] = new SqlParameter("@IDValue", str);
            p[3] = new SqlParameter("@Enabled", Enabled);
            count += _DB.updateData("bz_activeRecord" + _IDType, p);
        }
        return count;
    }
    public int insertRecord(string TitleVN, string TitleEN, string Price,
        string FirstPay, string DatePay, string Payment, 
        string FirstMonth, string EndMonth, string NameFull, string CMND,
        string Phone,string Address,
        string Email,string Trans,string Enabled, string Status)
    {
        SqlParameter[] p = new SqlParameter[16];
        p[0] = new SqlParameter("@TitleVN", TitleVN);
        p[1] = new SqlParameter("@TitleEN", TitleEN);
        p[2] = new SqlParameter("@Price", Price);
        p[3] = new SqlParameter("@FirstPay", FirstPay);
        p[4] = new SqlParameter("@DatePay",DatePay);
        p[5] = new SqlParameter("@Payment", Payment);
        p[6] = new SqlParameter("@FirstMonth", FirstMonth);
        p[7] = new SqlParameter("@EndMonth", EndMonth);
        p[8] = new SqlParameter("@NameFull", NameFull);
        p[9] = new SqlParameter("@CMND", CMND);
        p[10] = new SqlParameter("@Phone", Phone);
        p[11] = new SqlParameter("@Address", Address);
        p[12] = new SqlParameter("@Email", Email);
        p[13] = new SqlParameter("@Trans", Trans);     
        p[14] = new SqlParameter("@Enabled",Enabled);
        p[15] = new SqlParameter("@Status", Status);
        return _DB.updateData(_TableName + "_insert", p);
    }
    public int updateRecord(string ID,string Enabled)
    {
        SqlParameter[] p = new SqlParameter[2];
        p[0] = new SqlParameter("@ID", ID);
        p[1] = new SqlParameter("@Enabled", Enabled);
        return _DB.updateData(_TableName + "_update", p);
    }
    public DataTable getTableOther(string ID, string Page, string Limit, string Enabled, string Status)
    {
        SqlParameter[] p = new SqlParameter[5];
        p[0] = new SqlParameter("@ID", ID);
        p[1] = new SqlParameter("@Page", Page);
        p[2] = new SqlParameter("@Limit", Limit);
        p[3] = new SqlParameter("@Enabled", Enabled);
        p[4] = new SqlParameter("@Status", Status);
        return _DB.getDataTable(_TableName + "_other", p);
    }  
}
